package com.hm.handler.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;

/**
 * @author shishun.wang
 * @date 上午10:57:35 2016年5月31日
 * @version 1.0
 * @describe 
 */
@Component
public class ResponseUtil {
	
	private Properties properties;
	
	private void init() throws IOException{
		InputStream inputStream = this.getClass().getResourceAsStream("msg_response_state_ch.properties");
		properties = new Properties();
		properties.load(inputStream);
	}

	public boolean sendError(int state,HttpServletResponse response) throws IOException{
		if(null == properties){
			init();
		}
		response.setCharacterEncoding("UTF-8");
		response.setStatus(state);
		JSONObject item = new JSONObject();
		{
			item.put("result", properties.getProperty("STATE_"+state, "未知异常,请联系管理员"));
			item.put("message", "null");
		}
		response.getWriter().println(item.toJSONString());
		return false;
	}
}
